﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class Test_TestDBConnection : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Delete_CS(196);
        Delete_CS(195);
        Delete_CS(194);
        String cs;
        cs = ConfigurationManager.ConnectionStrings["CSConn"].ConnectionString;

        SqlConnection c = new SqlConnection(cs);
        SqlCommand cmd = new SqlCommand("SELECT * FROM Nationalities", c);
        SqlDataAdapter a = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        a.Fill(ds);

        GridView1.DataSource = ds;
        GridView1.DataBind();

        
    }

    protected void Insert_CS(String a)
    {
        String cs;
        cs = ConfigurationManager.ConnectionStrings["CSConn"].ConnectionString;

        SqlConnection c = new SqlConnection(cs);

        SqlCommand cmd2 = new SqlCommand("INSERT INTO Nationalities(NName) VALUES (@NName)", c);

        cmd2.Parameters.AddWithValue("@NName", a);

        c.Open();
        cmd2.ExecuteNonQuery();
        c.Close();

    }
    protected void Update_CS(String a, int x)
    {
        String cs;
        cs = ConfigurationManager.ConnectionStrings["CSConn"].ConnectionString;

        SqlConnection c = new SqlConnection(cs);

        SqlCommand cmd3 = new SqlCommand("UPDATE Nationalities SET NName = @NName WHERE NationalityID = @ID", c);

        cmd3.Parameters.AddWithValue("@NName", a);
        cmd3.Parameters.AddWithValue("@ID", x);

        c.Open();
        cmd3.ExecuteNonQuery();
        c.Close();

    }

    protected void Delete_CS(int x)
    {
        String cs;
        cs = ConfigurationManager.ConnectionStrings["CSConn"].ConnectionString;

        SqlConnection c = new SqlConnection(cs);

        SqlCommand cmd4 = new SqlCommand("DELETE FROM Nationalities WHERE NationalityID = @ID", c);

        cmd4.Parameters.AddWithValue("@ID", x);

        c.Open();
        cmd4.ExecuteNonQuery();
        c.Close();

    }
}